{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fdcd01dd",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests\n",
    "import pandas as pd\n",
    "import os\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "2f1ffff7",
   "metadata": {},
   "outputs": [],
   "source": [
    "# API参数\n",
    "API_URL = 'https://restapi.amap.com/v3/place/around'\n",
    "API_KEY = '64bc25f1a0ab839dbd425301309b7a96'  # 请确保这是你的有效API密钥\n",
    "LOCATION = '114.273801，30.59283'\n",
    "KEYWORDS = '快递网点'\n",
    "TYPES = '070500'\n",
    "RADIUS = 10000\n",
    "OFFSET = 25\n",
    "PAGE = 5\n",
    "EXTENSIONS = 'all'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "6a3ab0cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 构造完整的URL\n",
    "url = f'{API_URL}?key={API_KEY}&location={LOCATION}&keywords={KEYWORDS}&types={TYPES}&radius={RADIUS}&offset={OFFSET}&page={PAGE}&extensions={EXTENSIONS}'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "aa013ebf",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 发起请求并获取数据\n",
    "response = requests.get(url)\n",
    "data = response.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "61857795",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "数据已保存到：D:\\中诚大厦5.xlsx\n"
     ]
    }
   ],
   "source": [
    "# 提取需要的数据（这里假设返回的JSON结构是标准的）\n",
    "# 通常情况下，你需要根据实际的JSON结构来提取数据\n",
    "# 以下是一个示例性的代码片段\n",
    "locations_and_names = []\n",
    "if 'pois' in data:\n",
    "    for poi in data['pois']:\n",
    "        locations_and_names.append({\n",
    "            '目的地': poi['name'],\n",
    "            '目的地坐标': poi['location']\n",
    "        })\n",
    "\n",
    "# 将数据转换为DataFrame\n",
    "df = pd.DataFrame(locations_and_names)\n",
    "\n",
    "# 保存到Excel文件\n",
    "excel_path = os.path.join('D:\\\\', '良友大厦5.xlsx')  # 指定保存路径和文件名\n",
    "df.to_excel(excel_path, index=False, engine='openpyxl')  # 使用openpyxl引擎\n",
    "\n",
    "print(f'数据已保存到：{excel_path}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "975df0df",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "887d13c8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
